public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
    public int getMaxLen(int[] nums) {
        int n=nums.length;
        int[] f=new int[n+1];
        int[] g=new int[n+1];
        int ret=0;
        for(int i=1;i<=n;i++){
            if(nums[i-1]>0){
                f[i]=f[i-1]+1;
                g[i]=g[i-1]==0?0:g[i-1]+1;
            }
            else if(nums[i-1]<0){
                f[i]=g[i-1]==0?0:g[i-1]+1;
                g[i]=f[i-1]+1;
            }
            ret=Math.max(f[i],ret);
        }
        return ret;
    }
    int m,n;
    boolean[][] vis;
    int[] dx={-1,1,0,0};
    int[] dy={0,0,1,-1};
    int ret=0;
    public int getMaximumGold(int[][] grid) {
        m=grid.length;
        n=grid[0].length;
        vis=new boolean[m][n];
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                if(grid[i][j]!=0){
                    vis[i][j]=true;
                    dfs(grid,i,j,grid[i][j]);
                    vis[i][j]=false;
                }
            }
        }
        return ret;
    }
    public void dfs(int[][] g,int a,int b,int path){
        ret=Math.max(path,ret);
        for(int i=0;i<4;i++){
            int x=a+dx[i];
            int y=b+dy[i];
            if(x>=0&&x<m&&y>=0&&y<n&&!vis[x][y]&&g[x][y]!=0){
                vis[x][y]=true;
                dfs(g,x,y,g[x][y]+path);
                vis[x][y]=false;
            }
        }
    }
}